<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Bedingungen &mdash; PowerShell fuer Systemintegratoren</title>
    
    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    <link rel="top" title="PowerShell fuer Systemintegratoren" href="../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="Allgemeiner Index"
             accesskey="I">Index</a></li>
        <li><a href="../index.html">PS4SYS</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/PowerShell_icon_small.png" alt="Logo"/>
            </a></p>
  <h3>Diese Seite</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/loesung_rst/Loesung_PowerShell_Bedingungen.txt"
           rel="nofollow">Quelltext anzeigen</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Schnellsuche</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Los" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Geben Sie Suchbegriffe oder einen Modul-, Klassen- oder Funktionsnamen ein.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="bedingungen">
<h1>Bedingungen<a class="headerlink" href="#bedingungen" title="Permalink zu dieser Überschrift">¶</a></h1>
<ul class="simple" id="loesung-bedingungen">
<li>Mit welchen Vergleichsoperatoren können Sie in Bedingungen arbeiten ?</li>
</ul>
<div class="highlight-sh"><div class="highlight"><pre>-eq,  -ne,  -ge,  -gt,  -lt,  -le,  -like,  -notlike,  -match,  -notmatch,  -contains, -notcontains, -is, -isnot

-and, -or, -xor, -not
</pre></div>
</div>
<ul>
<li><p class="first">Folgende Variablen sind gegeben:</p>
<blockquote>
<div><blockquote>
<div><div class="highlight-sh"><div class="highlight"><pre><span class="nv">$user</span> <span class="o">=</span> <span class="s1">&#39;steinam&#39;</span>
<span class="nv">$pass</span> <span class="o">=</span> <span class="s1">&#39;passwort&#39;</span>
</pre></div>
</div>
</div></blockquote>
<p>Formulieren Sie eine Bedingung in Powershell, die gleichzeitig auf einen korrekten Usernamen und Passwort abfragt.</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="k">if</span><span class="o">(</span><span class="nv">$user</span> -ieq <span class="s1">&#39;STEINAM&#39;</span> -and <span class="nv">$pass</span> -eq <span class="s1">&#39;passwort&#39;</span><span class="o">)</span>
<span class="o">{</span>
        Write-Host <span class="s2">&quot;OK&quot;</span>
<span class="o">}</span>
<span class="k">else</span>
<span class="o">{</span>
        Write-Host <span class="s2">&quot;Fehler&quot;</span>
<span class="o">}</span>
</pre></div>
</div>
</div></blockquote>
</li>
</ul>
<ul>
<li><dl class="first docutils">
<dt>Mit Hilfe von WMI können Sie feststellen, welche Rolle ein Computer innerhalb einer Domäne spielt. Es gibt 6 verschiedene Rollen:</dt>
<dd><ul class="first simple">
<li>0 = Stand alone workstation</li>
<li>1 = Member Workstation</li>
<li>2 = Stand Alone Server</li>
<li>3 = Member Server</li>
<li>4 = Backup Domain Controller</li>
<li>5 = Primary Domain Controller</li>
</ul>
<p>Falls andere Werte zurückkommen, kann die Rolle nicht eindeutig definiert werden</p>
<p>Erstellen Sie ein Skript, welches die jeweilige Rolle in Textform ausgibt.</p>
<div class="last highlight-sh"><div class="highlight"><pre><span class="nv">$wmi</span> <span class="o">=</span> get-wmiobject win32_computersystem
<span class="s2">&quot;computer &quot;</span> + <span class="nv">$wmi</span>.name + <span class="s2">&quot; is: &quot;</span>

switch <span class="o">(</span><span class="nv">$wmi</span>.domainrole<span class="o">)</span>
<span class="o">{</span>
         0 <span class="o">{</span><span class="s2">&quot; Stand alone workstation&quot;</span><span class="o">}</span>
         1 <span class="o">{</span><span class="s2">&quot; Member workstation&quot;</span><span class="o">}</span>
         2 <span class="o">{</span><span class="s2">&quot; Stand alone server&quot;</span><span class="o">}</span>
         3 <span class="o">{</span><span class="s2">&quot; Member server&quot;</span><span class="o">}</span>
         4 <span class="o">{</span><span class="s2">&quot; Back up domain controller&quot;</span><span class="o">}</span>
         5 <span class="o">{</span><span class="s2">&quot; Primary domain controller&quot;</span><span class="o">}</span>
         default <span class="o">{</span><span class="s2">&quot; The role can not be determined&quot;</span><span class="o">}</span>
<span class="o">}</span>
</pre></div>
</div>
</dd>
</dl>
</li>
</ul>
<ul>
<li><p class="first">Drucker auf verschiedenen Betriebssystemen ermitteln</p>
<blockquote>
<div><p>Verschiedene Betriebssysteme nutzen manchmal unterschiedliche WMI Klassen und/oder Eigenschaften, so z.B. Windows XP, Windows 2003 und Windows 2000.
Sie wollen die auf diesen Betriebssystemen verwendeten Drucker auflisten und benötigen ein universell einsetzbares Skript.
Verwenden Sie ein if-Statement zum Ermitteln der korrekten OS-Version und verwenden Sie den dafür vorgesehenen Code.</p>
<p>Benutzen Sie die WMI-Klasse win32_OperatingSystem zum Ermitteln der OS-Version sowie win32_Printer auf XP und 2003 und win32_PrintJob auf Win2000-Systemen</p>
<div class="highlight-sh"><div class="highlight"><pre><span class="nv">$strComputer</span> <span class="o">=</span> Read-Host <span class="s2">&quot;Printer Report – Enter Computer Name&quot;</span>
<span class="nv">$OS</span> <span class="o">=</span> Get-WmiObject -Class win32_OperatingSystem -namespace <span class="s2">&quot;root\CIMV2&quot;</span> -ComputerName <span class="nv">$strComputer</span>

<span class="c"># if statement to run code for Windows XP and Windows 2003 Server.</span>
<span class="k">if</span> <span class="o">((</span><span class="nv">$OS</span>.Version -eq <span class="s2">&quot;5.1.2600&quot;</span><span class="o">)</span> -or <span class="o">(</span><span class="nv">$OS</span>.Version -eq <span class="s2">&quot;5.2.3790&quot;</span><span class="o">))</span>
<span class="o">{</span>
        write-host <span class="s2">&quot;Computer Name: &quot;</span> <span class="nv">$strComputer</span>
        <span class="c">#nested if statement</span>
        <span class="k">if</span> <span class="o">(</span><span class="nv">$OS</span>.Version -eq <span class="s2">&quot;5.1.2600&quot;</span><span class="o">)</span> <span class="o">{</span>write-host <span class="s2">&quot;OS Version: Windows XP&quot;</span><span class="o">}</span>
        elseif <span class="o">(</span><span class="nv">$OS</span>.Version -eq <span class="s2">&quot;5.2.3790&quot;</span><span class="o">)</span> <span class="o">{</span>write-host <span class="s2">&quot;OS Version: Windows 2003&quot;</span><span class="o">}</span>
                <span class="nv">$colPrinters</span> <span class="o">=</span> Get-WmiObject -Class win32_Printer -namespace <span class="s2">&quot;root\CIMV2&quot;</span> -computerName <span class="nv">$strComputer</span>
                        foreach <span class="o">(</span><span class="nv">$objPrinter</span> in <span class="nv">$colPrinters</span><span class="o">)</span> <span class="o">{</span>
                        write-host <span class="s2">&quot;Name: &quot;</span> <span class="nv">$objPrinter</span>.Name
                        write-host <span class="s2">&quot;Description: &quot;</span> <span class="nv">$objPrinter</span>.Description
                        write-host
                        <span class="o">}</span>
<span class="o">}</span>

<span class="c"># if statement to run code for Windows 2000 Server</span>
elseif <span class="o">(</span><span class="nv">$OS</span>.Version -eq <span class="s2">&quot;5.0.2195&quot;</span><span class="o">)</span>
<span class="o">{</span>
        write-host <span class="s2">&quot;Computer Name: &quot;</span> <span class="nv">$strComputer</span>
        write-host <span class="s2">&quot;OS Version: Windows 2000 Server&quot;</span>
                <span class="nv">$colPrinters</span> <span class="o">=</span> Get-WmiObject -Class win32_PrintJob -namespace <span class="s2">&quot;root\CIMV2&quot;</span> -computername <span class="nv">$strComputer</span>
                foreach <span class="o">(</span><span class="nv">$objPrinter</span> in <span class="nv">$colPrinters</span><span class="o">)</span> <span class="o">{</span>
                write-host <span class="s2">&quot;Name: &quot;</span> <span class="nv">$objPrinter</span>.Name
                write-host <span class="s2">&quot;Description: &quot;</span> <span class="nv">$objPrinter</span>.Description
                write-host
                <span class="o">}</span>
<span class="o">}</span>
<span class="c"># if OS not identified</span>
<span class="k">else</span> <span class="o">{</span>write-host <span class="s2">&quot;The OS for: $strComputer is not supported.&quot;</span><span class="o">}</span>
write-host <span class="s2">&quot;–END OF REPORT–&quot;</span>
</pre></div>
</div>
</div></blockquote>
</li>
</ul>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="Allgemeiner Index"
             >Index</a></li>
        <li><a href="../index.html">PS4SYS</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2010, STE.
      Mit <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1 erstellt.
    </div>
  </body>
</html>